package com.lu.sb210219.advice;

import com.lu.sb210219.exception.ApiException;
import com.lu.sb210219.result.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class ExceptionHandlerAdvice {

    @ExceptionHandler(ApiException.class)
    public Object exceptionHandler(ApiException e) {

        log.error(e.getMessage());

        e.printStackTrace();

        return JsonResult.builder().code(e.getCode()).msg(e.getMessage()).build();
    }

}
